package yhp.servlet;

import yhp.bean.Student;
import yhp.service.StudentService;
import yhp.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(urlPatterns = "/getstu")
public class StudentServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        StudentServiceImpl studentService = new StudentServiceImpl();
        List<Student> lookall = null;
        try {
            lookall = studentService.lookall();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        req.setAttribute("All",lookall);
        req.getRequestDispatcher("/success.jsp").forward(req,resp);
    }
}
